package com.lili.math;

/**
 * @Auther: 李 力
 * @Date: 2024/7/30
 * @Description: 比赛中的配对次数
 * @version: 1.0
 */
public class LeetCode1688 {

    /*
     * 时间复杂度: O(n)
     * 空间复杂度:O(1)
     */
    public int numberOfMatches(int n) {
        int count = 0;
        while (n > 1) {
            if (n % 2 == 0) {
                int num1 = n / 2;
                count = count + num1;
                n = n / 2;
            } else {
                int num2 = (n - 1) / 2;
                count = count + num2;
                n = (n - 1) / 2 + 1;
            }
        }
        return count;
    }
}
